import { getRights } from '@src/api/member'
Component({
  properties: {
    modul: {
      type: Object,
      value: {}
    },
    isMember: {
      type: Boolean,
      value: false
    },
    cardOrder: {
      type: Number
    },
    availableData: {
      type: Array
    }
  },
  lifetimes: {
    ready() {
      this.fetchData()
    }
  },
  pageLifetimes: {
    show: function() {
      // 页面被展示
      this.fetchData()
    },
  },
  data: {
    title: '',
    list: [],
    fileBaseUrl: '',
    levelData: []
  },

  methods: {
    getRights(rightsIds) {
      getRights(rightsIds)
      .then(res => {
        this.setData({list: res.data.list})
      })
    },
    fetchData() {
      const { availableData = [], cardOrder } = this.data
      let { params = {} } = this.data.modul.biz
      params = JSON.parse(params)
      params.ids?.length && this.getRights(params.ids)
      let fileBaseUrl = getApp().globalData.extConfig.fileBaseUrl
      const levelData = availableData.filter(item => cardOrder < item.category.cardOrder) 
      this.setData({title: params.title, fileBaseUrl, levelData})
    },
    toOpenCard() {
      wx.navigateTo({
        url: '/pages/indexChooseCard/main?categoryId=' + this.data.levelData[0].category.id
      })
    }
  }
})
